<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');

$shopId = $_GET['shopId'];
$serviceId = $_GET['serviceId'];
if( $shopId < 1 || $serviceId < 1 ){
	return ;
}
$deviceList = DeviceUse::GetListByShopIdAndServiceId($shopId, $serviceId);
$deviceIdList = array();

foreach ($deviceList as $key => $value) {
	
	$allOrderedCount = Preengage::GetOrderedCount($shopId, 0, $year, $month, $day, $startHour, $startMinute, $endHour, $endMinute);
		
	$allDeviceCount = Devices::GetDeviceCountForService($shopId);
	
	$deviceCount = Devices::GetDeviceCountForService($shopId, $serviceId);
	if( $allOrderedCount[0]['count'] >= $allDeviceCount[0]['count'] ){
		Logs::setLog("2 heihei buke<".$allOrderedCount[0]['count']."> <".$allDeviceCount[0]['count'].">");
		return false;
	}
	$orderedCount = Preengage::GetOrderedCount($shopId, $serviceId, $year, $month, $day, $startHour, $startMinute, $endHour, $endMinute);
	$deviceCount = Devices::GetDeviceCountForService($shopId, $serviceId);
	if( $orderedCount[0]['count'] >= $deviceCount[0]['count'] ){
		Logs::setLog("2 heihei buke<".$orderedCount[0]['count']."> <".$deviceCount[0]['count'].">");
		return false;
	}
	$deviceIdList[ $value['id'] ] = $value['device_name'];
}


Output::Json($staffIdList);

